package com.sf.proxy.chain;

import com.sf.proxy.proxy.RequestProto;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpResponse;

public class ChainContext {

    private FullHttpRequest request;

    private HttpResponse response;

    private ChannelHandlerContext ctx;

    private Channel clientChannel;

    private RequestProto requestProto;

    private String status;

    public ChainContext buildRequest(FullHttpRequest request){
        this.request = request;
        return this;
    }

    public ChainContext buildRespoense(HttpResponse response){
        this.response = response;
        return this;
    }

    public ChainContext buildResponseStatus(String status){
        this.status = status;
        return this;
    }

    public ChainContext buildChannelHandlerContext(ChannelHandlerContext channelHandlerContext){
        this.ctx  = channelHandlerContext;
        return this;
    }

    public ChainContext buildRequestProto(RequestProto requestProto){
        this.requestProto = requestProto;
        return this;
    }

    public ChainContext buildClientChannel(Channel clientChannel){
        this.clientChannel = clientChannel;
        return this;
    }

    private ChainContext(){

    }

    public String getRequestUrl(){
        if (request!=null){
            return request.uri();
        }
        return "";
    }

    public FullHttpRequest getRequest() {
        return request;
    }

    public HttpResponse getResponse() {
        return response;
    }

    public ChannelHandlerContext getCtx() {
        return ctx;
    }

    public Channel getClientChannel() {
        return clientChannel;
    }

    public static ChainContext getInstance(){
        return new ChainContext();
    }

    public RequestProto getRequestProto() {
        return requestProto;
    }

    public String getStatus() {
        return status;
    }
}
